package tedu.study.day07_2;

import java.util.Random;
import java.util.Scanner;

public class VerificationCode {
    public static void main(String[] args) {
        String code = generateVeriCode(6);
        System.out.println("验证码是："+code);
        code = createVeriCode(6);
        System.out.println("验证码是："+code);

        Scanner scan = new Scanner(System.in);
        String line = scan.nextLine();
        if(line.toLowerCase().equals(code.toLowerCase())){
            System.out.println("验证正确");
        }else{
            System.out.println("验证不通过");
        }
    }

    public static String generateVeriCode(int len){
        String code = "";
        char[] chs = {'q','w','e','r','t','y','u','i','o','p',
                'a','s','d','f','g','h','j','k','l',
                'z','x','c','v','b','n','m',
                'Q','W','E','R','T','Y','U','I','O','P',
                'A','S','D','F','G','H','J','K','L',
                'Z','X','C','V','B','N','M',
                '0','1','2','3','4','5','6','7','8','9'};
        Random rand = new Random();
        for(int i=1;i<=len;i++){
            int index = rand.nextInt(chs.length);
            code += chs[index];
        }
        return code;
    }

    public static String createVeriCode(int len){
        String code = "";
        String str="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789";
        Random rand = new Random();
        for(int i=1;i<=len;i++){
            int index = rand.nextInt(str.length());
            code += str.charAt(index);
        }
        return code;
    }
}
